
/*
* by huxy
* time: 2021-07-24
* dec： 带高程和地形的曲面
*/

export default class DrawLine {
    constructor() {
        this.length = 0;
        this.index = 0;
        this.DataSource = null;
    }
    init(positons, target) {
        viewer.scene.globe.depthTestAgainstTerrain = false;
        viewer.scene.fxaa = false
        viewer.scene.postProcessStages.fxaa.enabled = false;
        var supportsImageRenderingPixelated = viewer.cesiumWidget._supportsImageRenderingPixelated;
        if (supportsImageRenderingPixelated) {
            var vtxf_dpr = window.devicePixelRatio;
            while (vtxf_dpr >= 2.0) { vtxf_dpr /= 2.0; }
            viewer.resolutionScale = vtxf_dpr;
        }

        this.DataSource = null;
        // viewer.dataSources.removeAll();
        this.DataSource = this.DataSource || new Cesium.CustomDataSource('turnEntities');
        positons.forEach(item => {
            const pos = [];
            for (let i = 0; i < item.length; i += 2) {
                pos.push(Cesium.Cartesian3.fromDegrees(item[i], item[i + 1]))
            }
            this.DataSource.entities.add({
                polyline: {
                    positions: pos, //  Cesium.Cartesian3.fromDegrees(pos),
                    // positions: Cesium.Cartesian3.fromDegreesArrayHeights(pos),
                    width: 6.0,
                    clampToGround: true, //折线固定在地面
                    // material: new Cesium.PolylineGlowMaterialProperty({
                    //     color: Cesium.Color.DEEPSKYBLUE,
                    //     glowPower: 0.25,
                    // }),
                    material: new Cesium.PolylineOutlineMaterialProperty({
                        color: Cesium.Color.ORANGE,
                        outlineWidth: 1,
                        outlineColor: Cesium.Color.BLACK,
                    }),
                },
            });

        })
        // const pos = [];
        // positons.forEach(item => {
        //     pos.push(item['lon'])
        //     pos.push(item['lat'])
        //     pos.push(item['height'])
        // });
        // this.DataSource.entities.add({
        //     polyline: {
        //         positions: Cesium.Cartesian3.fromDegreesArrayHeights(pos),
        //         width: 10.0,
        //         clampToGround: true, //折线固定在地面
        //         material: new Cesium.PolylineGlowMaterialProperty({
        //             color: Cesium.Color.DEEPSKYBLUE,
        //             glowPower: 0.25,
        //         }),
        //     },
        // });

        viewer.dataSources.add(this.DataSource);
        viewer.flyTo(this.DataSource);
    }
    drawTheBillboard(lon, lat, h) {
        this.DataSource.entities.add({
            position: Cesium.Cartesian3.fromDegrees(lon, lat, h),
            billboard: {
                image: require("../../assets/materialImg/point1.png"),  // "../../../asset/materialImg/line-markder.png",
                width: 48,
                height: 48,
                scale: 0.5,
                sizeInMaters: true,
                // clampToGround: true, //折线固定在地面
            }
        })
        viewer.flyTo(this.DataSource);
    }
}